package cn.imvc.app.controllers;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.imvc.app.entities.Account;
import cn.imvc.app.entities.Dealer;
import cn.imvc.app.entities.Member;
import cn.imvc.app.models.AccountModel;
import cn.imvc.app.models.GoodsClassModel;
import cn.imvc.app.models.IndexModel;
import cn.imvc.app.models.MemberModel;
import cn.imvc.app.models.TypeValueModel;

@Controller
public class IndexControllerImpl implements IndexController {

	@Autowired
	MemberModel memberModel;
	@Autowired
	IndexModel indexModel;
	@Autowired
	GoodsClassModel goodsClassModel;
	@Autowired
	TypeValueModel typeValueModel;
	@Autowired
	AccountModel accountModel;
	
	@RequestMapping("/index.html")
	public String index(String token, Model model) {
		// 获取首页需要显示的内容
		Byte platForm = 1;
		Map<String, Object> result = indexModel.getShowDate(platForm);
		model.addAllAttributes(result);
		/*
		Member member = memberModel.getLoginMember(token);
		if(member!=null){
			member = memberModel.get(member.getId());
			Account account = member.getAccount();
			model.addAttribute("points", account.getPoints());
			model.addAttribute("purse", account.getPurse());
			Dealer dealer = member.getDealer();
			model.addAttribute("dealerlevel", dealer.getDealerLevel());
		}
		model.addAttribute("member", member);*/
		return "index/index";
	}
	@RequestMapping("/getIndexHeader.html")
	public String getIndex(String token, Model model) {
		Member member = memberModel.getLoginMember(token);
		if(member!=null){
			member = memberModel.get(member.getId());
			Account account = member.getAccount();
			model.addAttribute("points", account.getPoints());
			model.addAttribute("purse", account.getPurse());
			Dealer dealer = member.getDealer();
			model.addAttribute("dealerlevel", dealer.getDealerLevel());
		}
		model.addAttribute("member", member);
		return "index/index";
	}

	@RequestMapping("/index.htm")
	public String pcindex(Model model) {
		// 获取首页需要显示的内容
		Byte platForm = 2;
		Map<String, Object> result = indexModel.getShowDate(platForm);
		model.addAllAttributes(result);
		return "index/pcindex";
	}

	@RequestMapping("/indexHeader.htm")
	public String pcheader(String token, String keyWord, Model model) {
		Member member = memberModel.getLoginMember(token);
		Integer showType =206;
		byte platform = 2;
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("showType", showType);
		paramMap.put("platform", platform);
		Map<String,Object> headerInfos = indexModel.getHeaderInfos(paramMap);
		model.addAttribute("member", member);
		model.addAllAttributes(headerInfos);
		return "layout/header1";
	}

}
